package com.hellobike.haxing.web.shop;

import com.alibaba.fastjson.JSON;
import com.hellobike.haxing.order.api.IOrderStatsService;
import com.hellobike.haxing.order.model.request.UserStatsRequest;
import com.hellobike.haxing.order.model.vo.UserStatsVo;
import com.hellobike.haxing.order.result.PageResult;
import com.hellobike.haxing.request.PageRequest;
import com.hellobike.haxing.util.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "/customer")
@Api(tags = "客户数据接口")
public class CustomerController {

    @Reference(version = "1.0.0")
    private IOrderStatsService orderStatsService;

    @Autowired
    private UserUtil userUtil;

    @PostMapping(value = "/day-customer")
    @ApiOperation("今日客户")
    public PageResult<UserStatsVo> dayCustomer(@RequestBody PageRequest request) {
        UserStatsRequest userStatsRequest = new UserStatsRequest();
        userStatsRequest.setShopId(userUtil.getUser().getShopVo().getId());
        userStatsRequest.setCurPage(request.getCurPage());
        userStatsRequest.setPageSize(request.getPageSize());
        log.info("response:-->{}", JSON.toJSONString(request));
        return orderStatsService.stats(userStatsRequest);
    }
}
